package steed.ext.task;

import java.util.List;
import java.util.Random;

import steed.domain.wechat.WechatAccount;
import steed.hibernatemaster.util.DaoUtil;
import steed.util.base.BaseUtil;
import steed.util.system.SimpleTaskEngine;
import steed.util.wechat.MutiAccountSupportUtil;
import steed.util.wechat.WechatInterfaceInvokeUtil;

public class SynchronizationUsersTask extends SimpleTaskEngine{

	@Override
	public void doTask() {
		List<WechatAccount> listAllObj = DaoUtil.listAllObj(WechatAccount.class);
		for (WechatAccount temp:listAllObj) {
			synchronizationUsers(temp);
		}
	}
	
	public void synchronizationUsers(WechatAccount wechatAccount){
		try {
			MutiAccountSupportUtil.setWechatAccount(wechatAccount);
			WechatInterfaceInvokeUtil.synchronizationUsers(false, true);
		}catch (Exception e) {
			BaseUtil.getLogger().error("同步"+wechatAccount.getAppID()+"的粉丝出错!",e);
		} finally {
			DaoUtil.managTransaction();
			DaoUtil.closeSessionNow();
		}
		BaseUtil.getLogger().info("同步"+wechatAccount.getAppID()+"的粉丝成功!");
	}

}
